package com.ym.b2b.complaint.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ym.b2b.commons.exception.BaseException;
import com.ym.b2b.commons.service.BaseService;
import com.ym.b2b.complaint.dao.EmBComplaintDAO;
import com.ym.b2b.complaint.dao.EmBReplyDAO;
import com.ym.b2b.complaint.service.EmBReplyService;
import com.ym.b2b.complaint.sqlbean.EmBComplaint;
import com.ym.b2b.complaint.sqlbean.EmBReply;
import com.zc.commons.base.Page;
import com.zc.commons.base.Result;

@Service
public class EmBReplyServiceImpl extends BaseService implements EmBReplyService {

    @Autowired
    private EmBReplyDAO replyDao;
    @Autowired
    private EmBComplaintDAO complaintDao;

    @Override
    public Result searchPageEmBReply(EmBReply emBReply, Page<EmBReply> page) {
        // TODO Auto-generated method stub
        Result result = new Result();
        try {
            result.setResultPage(replyDao.searchPageEmBReply(emBReply, page));
        } catch (Exception e) {
            throw new BaseException(Result.CODE_100, "查询异常");
        }
        return result;
    }

    @Override
    public int deleteEmBReply(Long replyId) {
        int result = replyDao.deleteEmBReply(replyId);
        return result;
    }

    @Override
    public int deleteMultipleEmBReply(String replyIdList) {
        int rows = replyDao.deleteMultipleEmBReply(replyIdList);
        return rows;
        
    }

    @Override
    public Result updateEmBReply(EmBReply emBReply) {
        Result result = new Result();
        try {
            replyDao.updateEmBReply(emBReply);
            result.setResult("修改信息成功!");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new BaseException(Result.CODE_100, "修改信息失败!");
        }
        return result;
    }

    @Override
    public Result updateEmBReplyBat(EmBReply emBReply) {
        Result result = new Result();
        try {
            replyDao.updateEmBReplyBat(emBReply);
            result.setResult("修改信息成功!");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new BaseException(Result.CODE_100, "修改信息失败!");
        }
        return result;
    }

    @Override
    public EmBReply searchEmBReply(EmBReply emBReply) {
        // TODO Auto-generated method stub
        EmBReply result = new EmBReply();
        result = replyDao.searchEmBReply(emBReply.getReplyId());
        return result;
    }

    @Transactional
    @Override
    public Result insertEmBReply(EmBReply emBReply) {
        Result result = new Result();
        try {
            EmBComplaint record = new EmBComplaint();
            record.setComplaintId(emBReply.getComplaintId());
            record.setRepplyStatus(1);
            complaintDao.updateEmBComplaint(record);
            replyDao.insertEmBReply(emBReply);
            result.setResult("添加信息成功!");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new BaseException(Result.CODE_100, "添加信息失败!");
        }
        return result;
    }

}
